//
//  AdoptBugCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/6.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "AdoptBugCell.h"

@interface AdoptBugCell ()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *diccountLab;
@property (nonatomic, strong) UILabel *youhuiLab;
@property (nonatomic, strong) UILabel *priceLab;
@property (nonatomic, strong) UILabel *dayLab;
@property (nonatomic, strong) UIImageView *starIcon;
@property (nonatomic, strong) UIImageView *selectedIcon;
@property (nonatomic, strong) UIImageView *recommedIcon;
@property (nonatomic, strong) UIImageView *bgIcon;

@end


@implementation AdoptBugCell

#pragma mark - lifecycle methods

- (void)setupUI
{
    [self addSubview:self.bgIcon];
    
}

- (void)setupLayout
{
    {
        _bgIcon.size = CGSizeMake(KScreenWidth - 30, 114);
        _bgIcon.mj_x = 15;
        _bgIcon.mj_y = 20;
    }
    
    {
        _titleLab.size  = CGSizeMake(80, 24);
        _titleLab.mj_x = 36;
        _titleLab.mj_y = 31;
    }
    
    {
        _starIcon.size = CGSizeMake(21, 21);
        _starIcon.mj_y = 21;
        _starIcon.mj_x = 18;
    }
    
    {
        _youhuiLab.size = CGSizeMake(48, 19);
        _youhuiLab.mj_y = 33;
        _youhuiLab.mj_x = _titleLab.right + 2;
    }
    
    {
        _recommedIcon.size = CGSizeMake(24, 24);
        _recommedIcon.mj_y = 0;
        _recommedIcon.mj_x = _bgIcon.width - _recommedIcon.width;
    }
    
    {
        _priceLab.size = CGSizeMake(100, 26);
        _priceLab.mj_y = 44;
        _priceLab.mj_x = KScreenWidth - _priceLab.width - 34;
    }
    
    {
        _selectedIcon.size = CGSizeMake(18, 18);
        _selectedIcon.mj_y = _bgIcon.height - _selectedIcon.height - 18;
        _selectedIcon.mj_x = _bgIcon.width - _selectedIcon.width - 8;
    }
    
    {
        _dayLab.size = CGSizeMake(200, 24);
        _dayLab.mj_x = 36;
        _dayLab.mj_y = 64;
    }
}

#pragma mark - setter methods

- (void)setItem:(AdoptDetail *)item{
    
    NSString *price = [NSString stringWithFormat:@"¥%@", item.money];
    NSString *day = [NSString stringWithFormat:@"%@天", item.day];
    NSString *text = [NSString stringWithFormat:@"%@ %@", price, day];

    NSMutableAttributedString *aims = [[NSMutableAttributedString alloc] initWithString:text];
    [aims addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xF25C62) range:NSMakeRange(0, price.length)];
    [aims addAttribute:NSFontAttributeName value:mMediumFont(17) range:NSMakeRange(0, price.length)];
    [aims addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x999999) range:NSMakeRange(price.length+1, day.length)];
    [aims addAttribute:NSFontAttributeName value:mFont(14) range:NSMakeRange(price.length+1, day.length)];
    _dayLab.attributedText = aims;
    
    _priceLab.text = [NSString stringWithFormat:@"优惠 ¥ %@", item.discountPrice];
    
    float num = [item.discountPrice floatValue] /[item.money floatValue];
    float youhuiNum = 1 - num;
    NSString *youhuiStr = [NSString stringWithFormat:@"%.2f", youhuiNum];
    _youhuiLab.text = [NSString stringWithFormat:@"%@折", [youhuiStr substringFromIndex:2]];
    
    _selectedIcon.image = item.isSelect ?[UIImage imageNamed:@"adopt_buy_selected"] :[UIImage imageNamed:@"meat_cart_unchecked"];
    
}

#pragma mark - getter methods

- (UIImageView *)bgIcon{
    
    if (!_bgIcon) {
        _bgIcon = [[UIImageView alloc] init];
        _bgIcon.image = [UIImage imageNamed:@"pay_detail_big"];
        
        [_bgIcon addSubview:self.starIcon];
        [_bgIcon addSubview:self.selectedIcon];
        [_bgIcon addSubview:self.recommedIcon];
        [_bgIcon addSubview:self.titleLab];
        [_bgIcon addSubview:self.youhuiLab];
        [_bgIcon addSubview:self.priceLab];
        [_bgIcon addSubview:self.dayLab];

    }
    return _bgIcon;
}

- (UIImageView *)starIcon{
    
    if (!_starIcon) {
        _starIcon = [[UIImageView alloc] init];
        _starIcon.image = [UIImage imageNamed:@"pay_star"];
    }
    return _starIcon;
}

- (UIImageView *)selectedIcon{
    
    if (!_selectedIcon) {
        _selectedIcon = [[UIImageView alloc] init];
        _selectedIcon.image = [UIImage imageNamed:@"meat_cart_unchecked"];
    }
    return _selectedIcon;
}

- (UIImageView *)recommedIcon{
    
    if (!_recommedIcon) {
        _recommedIcon = [[UIImageView alloc] init];
        _recommedIcon.image = [UIImage imageNamed:@"pay_recommend"];
    }
    return _recommedIcon;
}

- (UILabel *)titleLab{
    
    if (!_titleLab) {
        _titleLab = [UILabel makeLabelWithText:@"托管全包" textColor:UIColorFromRGB(0x333333) font:mMediumFont(17) textAliment:0];
    }
    return _titleLab;
}

- (UILabel *)youhuiLab{
    
    if (!_youhuiLab) {
        _youhuiLab = [UILabel makeLabelWithText:@"85折" textColor:KWhiteColor font:mFont(12) textAliment:1];
        _youhuiLab.backgroundColor = UIColorFromRGB(0xFF8A00);
        [self addShadowAndCircleCorner:_youhuiLab.layer corner:3];
    }
    return _youhuiLab;
}

- (UILabel *)priceLab{
    
    if (!_priceLab) {
        _priceLab = [UILabel makeLabelWithText:@"优惠¥400" textColor:UIColorFromRGB(0xFF8A00) font:mMediumFont(19) textAliment:0];
    }
    return _priceLab;
}

- (UILabel *)dayLab{
    
    if (!_dayLab) {
        _dayLab = [UILabel makeLabelWithText:@"¥3000" textColor:UIColorFromRGB(0xF25C62) font:mMediumFont(19) textAliment:0];
    }
    return _dayLab;
}


@end
